package org.candan.spider.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyParse {
	private  static String PROPERTYFILE = "spiderx.properties";	
	private static Properties props= null;
	public static  String getValue(String key){
//		System.out.println("PROPERTYFILE: "+PROPERTYFILE);
		return getProperties().getProperty (key);          
	}
	public static Properties getProperties(){
		if(props == null){
	        try {
	        	InputStream in = new BufferedInputStream(getResourceAsStream(PROPERTYFILE)); 
	        	props= new Properties();
				props.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			}          
		}
		return props;
	}
	public static InputStream getResourceAsStream(String resource) throws IOException {
	    InputStream in = null;
	    ClassLoader loader = PropertyParse.class.getClassLoader();
//	    System.out.println(loader.get);
	    if (loader != null) in = loader.getResourceAsStream(resource);
	    if (in == null) in = ClassLoader.getSystemResourceAsStream(resource);
	    if (in == null) throw new IOException("Could not find resource " + resource);
	    return in;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
